﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RgUtility.OrmForOracle.Tool
{
    public class SqlLogTool
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pArr"></param>
        /// <returns></returns>
        public static string GetExecutedSql(string sql, Oracle.DataAccess.Client.OracleParameter[] pArr)
        {
            foreach (var item in pArr)
            {
                if (item.Value is System.Int16
                    || item.Value is System.Int32
                    || item.Value is System.Int64
                    || item.Value is float
                    || item.Value is decimal
                    ||item.Value is double
                    )
                {
                    sql = sql.Replace(item.ParameterName, item.Value + "");
                }
                else if(item.Value is string)
                {
                    sql = sql.Replace(item.ParameterName, "'" + item.Value + "'");
                }
                else if (item.Value is DateTime)
                {
                    sql = sql.Replace(item.ParameterName, "to_date('" + ((DateTime)item.Value).ToString("yyyy/MM/dd HH:mm:ss") + "','yyyy/MM/dd HH24:mi:ss')");
                }
                else
                {
                    sql = sql.Replace(item.ParameterName, "'" + item.Value + "'");
                }
            }
            return sql+";";
        }
    }
}
